#include <bits/stdc++.h>
#define int long long
using int128 = __int128_t;
using namespace std;
int mod, n;

class Matrix {
public:
    int128 n, m, a[5][5];
    Matrix(int N, int M)
    {
        n = N, m = M;
        memset(a, 0, sizeof a);
    }
    Matrix operator*(Matrix& b)
    {
        Matrix c(n, b.m);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= b.m; j++)
                for (int k = 1; k <= m; k++)
                    c.a[i][j] += a[i][k] * b.a[k][j], c.a[i][j] %= mod;
        return c;
    }
};

Matrix quick_pow(Matrix a, int128 k)
{
    Matrix ans(a.n, a.n);
    for (int i = 1; i <= a.n; i++)
        ans.a[i][i] = 1;
    while (k) {
        if (k & 1)
            ans = ans * a;
        a = a * a;
        k >>= 1;
    }
    return ans;
}

int128 quick_pow(int128 a, int128 k)
{
    int128 ans = 1;
    while (k) {
        if (k & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        k >>= 1;
    }
    return ans;
}

int128 solve(int128 n, int128 k)
{
    Matrix a(3, 3);
    Matrix b(3, 1);
    a.a[1][1] = k * 10, a.a[1][2] = 1, a.a[1][3] = 1;
    a.a[2][2] = 1, a.a[2][3] = 1;
    a.a[3][3] = 1;
    b.a[1][1] = 0, b.a[2][1] = k - 1, b.a[3][1] = 1;
    return (quick_pow(a, n - k + 1) * b).a[1][1];
}

signed main()
{
    cin >> n >> mod;
    int128 ans = 0, k = 1;
    while (n >= k) {
        ans = ans * quick_pow(k * 10, min(k * 10 - 1, (int128)n) - k + 1) + solve(min(k * 10 - 1, (int128)n), k), ans %= mod, k *= 10;
    }
    cout << (int)(ans % mod);
    return 0;
}